﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TlvLib.SiChuan.Packet;

namespace TlvLib.SiChuan.Unpacker
{
    class DataReportReplyUnpacker
    {
        public static bool TryUnpack(byte[] buffer, out DataReportReply dataReportReply)
        {
            dataReportReply = null;
            if (!Helper.IsValid(buffer))
            {
                return false;
            }

            if (Helper.GetPacketType(buffer) != PacketType.DataReport)
            {
                return false;
            }

            var sn = Configuration.EndianBitConverter.ToUInt32(buffer, 8);
            var res = (DataReportResult)Configuration.EndianBitConverter.ToUInt16(buffer, 12);

            dataReportReply = new DataReportReply() { Result = res, SN = sn };
            return true;
        }
    }
}
